<?php
$app = Blyn::app()->getActiveApp();
?>
<?php
$model = new BDynamicFormModel();
$attributeNameField = 'media_name_product_attribute';
$attributeAliasField = 'media_alias_product_attribute';
$attributeTypeField = 'media_type_product_attribute';
$model->addField($attributeNameField);
$model->addField($attributeAliasField);
$model->addField($attributeTypeField);

$attributeView = array();
if ($productId > 0) {
    //first get product
    $productTable = new BPProductSheet('product');
    $product = $productTable->getListById($productId);
    $attributeTable = new BPProductSheet('productAttribute', $product);

    $attributeView = $attributeTable->getView();
}
?>
<div class="well row-fluid">
    <div class="input-prepend span3">
        <span class="add-on">属性名</span>
        <?php
        echo CHtml::activeTextField($model, $attributeNameField, array('placeholder' => 'attribute' . '...', 'required' => true, 'class' => 'span9'));
        ?>
    </div>
    <div class="input-prepend span3">
        <span class="add-on">别名</span>
        <?php
        echo CHtml::activeTextField($model, $attributeAliasField, array('placeholder' => 'alias' . '...', 'required' => true, 'class' => 'span9'));
        ?>
    </div>
    <div class="input-prepend span3">
        <span class="add-on">类型</span>
        <?php
        $typeList = $app->getDataTypeList();
        echo CHtml::activeDropDownList($model, $attributeTypeField, $typeList, array('required' => true, 'class' => 'span8'));
        ?>
    </div>
    <div class="input-append span2">
        <?php
        echo $control->getAjaxLink(array('name' => '设置数据', 'id' => 'setDataTypeType'), array(
            'htmlOptions' => array('class' => 'btn'),
            'productId' => $productId,
            'attributeId' => 0
        ));
        ?>
        <?php
        echo $control->getAjaxLink(array('name' => '添加属性', 'id' => 'addProductAttribute'), array(
            'htmlOptions' => array('class' => 'btn'),
            'productId' => $productId,
            'attributeId' => 0
        ));
        ?>
    </div>

</div>
<?php if (count($attributeView) > 0) { ?>
    <div style="min-height: 100px">
        <table class="table table-hover">
            <colgroup>
                <col class="span1">
                <col class="span3">
                <col class="span3">
                <col class="span3">
                <col class="span3">
            </colgroup>
            <thead>
                <tr>
                    <th></th>
                    <th><?php echo '属性'; ?></th>
                    <th><?php echo '别名'; ?></th>
                    <th><?php echo '类型'; ?></th>
                    <th><?php echo '操作'; ?></th>
                </tr>
            </thead>
            <tbody>
                <?php
                foreach ($attributeView as $productAttribute) {
                    $nameItem = $productAttribute->getItem('name');
                    $typeItem = $productAttribute->getItem('type');
                    $aliasItem = $productAttribute->getItem('alias');
                    $name = '';
                    $type = '';
                    $alias = '';
                    $attributeValue = '';
                    if ($nameItem instanceof BTreeItem) {
                        $name = $nameItem->getValue();
                    }
                    if ($typeItem instanceof BTreeItem) {
                        $type = $typeItem->getValue();
                    }
                    if ($aliasItem instanceof BTreeItem) {
                        $alias = $aliasItem->getValue();
                    }
                    ?>
                    <tr><td><input type="checkbox"></td>
                        <td> <?php
                            echo $name;
                            ?> </td>
                        <td>
                            <?php
                            echo $alias;
                            ?>
                        </td>
                        <td>
                            <?php
                            echo $type;
                            ?>
                        </td>
                        <td>
                            <?php
                            echo $control->getAjaxLink('修改');
                            echo ' | ';
                            echo $control->getAjaxLink('删除');
                            ?>
                        </td>

                    </tr>   
                <?php } ?>
            </tbody>
        </table>
    </div>
<?php } ?>




